package com.tengfei.api.user;

import com.tengfei.common.core.domain.R;
import com.tengfei.main.exam.domain.vo.PaperVo;
import com.tengfei.main.user.domain.vo.exam.UserPaperInitVo;
import com.tengfei.main.user.domain.vo.exam.UserPaperVo;
import com.tengfei.main.user.service.IUserExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @author feige
 * @version v1.0
 * @date 2022-09-13-21:26
 * @description 普通用户考试模块控制器
 */
@RestController
@RequestMapping("/user/exam")
@Api(value = "用户考试控制器", tags = {"用户考试模块"})
public class UserExamController {

    @Resource
    private IUserExamService examService;


    /**
     * 查询用户试卷列表
     *
     * @param paperStatus
     * @param status
     * @param paperName
     * @return
     */
    @GetMapping("/paper/list")
    @ApiOperation("查询用户试卷列表")
    public R<List<UserPaperVo>> getPaperList(@ApiParam("试卷状态(0:未开始,1:已开始,2:已结束)")
                                             @RequestParam(value = "paperStatus", required = false) Integer paperStatus,
                                             @ApiParam("用户考试状态(0:未考试,1:考试中,2:已交卷)")
                                             @RequestParam(value = "status", required = false) Integer status,
                                             @ApiParam("试卷名称")
                                             @RequestParam(value = "paperName", required = false) String paperName) {
        return R.ok(examService.getPaperList(paperStatus, status, paperName));
    }

    /**
     * 查询所有试卷列表
     *
     * @param paperStatus
     * @param paperName
     * @return
     */
    @GetMapping("/paper/allList")
    @ApiOperation("查询所有试卷列表")
    public R<List<PaperVo>> getAllPaperList(@ApiParam("试卷状态(0:未开始,1:已开始,2:已结束)")
                                            @RequestParam(value = "paperStatus", required = false) Integer paperStatus,
                                            @ApiParam("试卷名称")
                                            @RequestParam(value = "paperName", required = false) String paperName) {
        return R.ok(examService.getAllPaperList(paperStatus, paperName));
    }

    /**
     * 查询试卷详细信息，通过id
     *
     * @param paperId
     * @return
     */
    @GetMapping("/paper/info")
    @ApiOperation("查询试卷详细信息通过id")
    public R<UserPaperVo> getUserPaperById(@ApiParam("试卷Id") @NotNull(message = "试卷id不能为空")
                                           @RequestParam(value = "paperId") Long paperId) {
        return examService.getUserPaperById(paperId);
    }

    /**
     * 初始化试卷/继续考试
     *
     * @param paperId
     * @return
     */
    @PostMapping("/paper/init")
    @ApiOperation("初始化试卷/继续考试,开始考试")
    public R<UserPaperInitVo> initPaper(@ApiParam(value = "试卷id", required = true) @RequestParam("paperId")
                                        @NotNull(message = "试卷id不能为空") Long paperId) {
        return examService.initPaper(paperId);
    }

    /**
     * 查询试卷题目详细信息
     *
     * @param quId
     * @param paperId
     * @return
     */
    @GetMapping("/paper/quInfo")
    @ApiOperation("查询试卷题目详细信息")
    public R<Object> quInfo(@ApiParam(value = "题目id", required = true) @NotNull(message = "题目id不能为空")
                            @RequestParam("quId") Long quId,
                            @ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为空")
                            @RequestParam("paperId") Long paperId,
                            @ApiParam(value = "题目类型", required = true) @NotNull(message = "题目类型不能为空")
                            @RequestParam("quType") Integer quType) {
        return examService.quInfo(quId, paperId, quType);
    }

    /**
     * 上传试卷题目答案
     *
     * @param quId
     * @param paperId
     * @param userAns
     * @return
     */
    @PostMapping("/paper/uploadAns")
    @ApiOperation("上传试卷题目答案")
    public R<Void> uploadQuAns(@ApiParam(value = "题目id", required = true) @NotNull(message = "题目id不能为空")
                               @RequestParam("quId") Long quId,
                               @ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为空")
                               @RequestParam("paperId") Long paperId,
                               @ApiParam(value = "用户答案", required = true) @NotNull(message = "用户答案不能为空不能为空")
                               @RequestParam("userAns") String userAns) {
        return examService.uploadQuAns(quId, paperId, userAns);
    }

    /**
     * 交卷
     *
     * @param paperId
     * @return
     */
    @PostMapping("/paper/submit")
    @ApiOperation("交卷")
    public R<Void> submitPaper(@ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为kong")
                               @RequestParam("paperId") Long paperId) {
        return examService.submitPaper(paperId);
    }

    /**
     * 试卷题目作答详情
     *
     * @param paperId
     * @return
     */
    @GetMapping("/paper/ansList")
    @ApiOperation("试卷题目作答详情")
    public R<List> ansInfoList(@ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为空")
                               @RequestParam("paperId") Long paperId) {
        return examService.ansInfoList(paperId);
    }

    /**
     * 试卷作答详情
     *
     * @param paperId
     * @return
     */
    @GetMapping("/paper/examInfo")
    @ApiOperation("试卷作答详情")
    public R<Void> examInfo(@ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为空")
                            @RequestParam("paperId") Long paperId) {
        return examService.examInfo(paperId);
    }

    /**
     * 查询当前试卷用户排名
     *
     * @param paperId
     * @return
     */
    @ApiOperation("当前试卷用户排名信息")
    @GetMapping("/paper/userRank")
    public R<List<Map<String, Object>>> userRanking(@ApiParam(value = "试卷id", required = true) @NotNull(message = "试卷id不能为空")
                                                    @RequestParam("paperId") Long paperId) {
        return examService.userRank(paperId);
    }


}
